#ifndef TITLEBAR_H
#define TITLEBAR_H

#include <QWidget>
#include <QHBoxLayout>

class Button;
class QLabel;
class TitleBar : public QWidget
{
    Q_OBJECT
public:
    explicit TitleBar(QWidget *parent = 0);
    explicit TitleBar(bool simple, QWidget *parent = 0);

    // 插入一个布局到TitleBar
    void insertUserLayout(QLayout *UserLayout, int pos, int stretch);
    // 插入一个窗口到TitleBar的布局中
    void insertUserWidget(QWidget *widget, int index, int stretch = 0, Qt::Alignment alignment = 0);
    void setTitleName(QString name);
    void setMainWindow(QWidget* parent);
    void setMoveable(bool isMove);

signals:
    void closeWin();
    void minimumWin();
    void showMenu();
    void skinChange();
    void updateVersion();

protected:
    void mousePressEvent(QMouseEvent* event);
    void mouseMoveEvent(QMouseEvent *event);

private:
    // 初始化通用控件
    void initCommonControls();
    // 初始化当前窗口布局
    void initToolBarLayout(bool isSimple = false);

private:
    // 按钮
    Button *m_closeBtn;
    Button *m_minimizeBtn;
    Button *m_menuBtn;
    Button *m_skinBtn;
    Button *m_updateBtn;
    QLabel *m_titleName;
    // 布局
    QHBoxLayout* m_layout;
    // 鼠标拖动窗口先关数据
    bool m_isMove = false;  // 控制窗口是否需要通过鼠标控制移动
    QPoint m_pt;
    QWidget* m_parent;
};


#endif // TITLEBAR_H
